package com.controller.biz;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.IdUtil;
import com.common.log.Log;
import com.common.util.ResultUtil;
import com.entity.biz.BizBook;
import com.entity.sys.query.SysQuery;
import com.service.biz.BizBookService;
import org.springframework.web.bind.annotation.*;

import com.common.base.BaseController;

/**
 * 书籍 前端控制器
 */
@RestController
@RequestMapping("/biz/book")
public class BizBookController extends BaseController<BizBookService, BizBook> {

    /**
     * 书籍列表
     */
    @GetMapping("/list")
    @SaCheckPermission("business:book:view")
    public ResultUtil list(SysQuery query) {
        return ResultUtil.success(service.page(query));
    }

    /**
     * 详情
     */
    @GetMapping("/getById/{id}")
    public ResultUtil getById(@PathVariable("id") String id) {
        return ResultUtil.success(service.getById(id));
    }

    /**
     * 新增
     */
    @Log(title = "新增书籍")
    @PostMapping("/insert")
    @SaCheckPermission("business:book:add")
    public ResultUtil insert(@RequestBody BizBook bizBook) {
        bizBook.setId(IdUtil.getSnowflakeNextIdStr());
        service.save(bizBook);
        return ResultUtil.success();
    }

    /**
     * 修改
     */
    @Log(title = "修改书籍")
    @PostMapping("/update")
    @SaCheckPermission("business:book:update")
    public ResultUtil update(@RequestBody BizBook bizBook) {
        service.updateById(bizBook);
        return ResultUtil.success();
    }

    /**
     * 删除
     */
    @Log(title = "删除书籍")
    @GetMapping("/delete/{id}")
    @SaCheckPermission("business:book:delete")
    public ResultUtil delete(@PathVariable("id") String id) {
        service.removeById(id);
        return ResultUtil.success();
    }
}
